/***
 * @desc 群组
 * 
 */
const group = {

  getGoup(shareTicket) {
    return new Promise((resolve, reject) => {
      wx.getShareInfo({
        shareTicket: shareTicket,
        success: function (res) {
          console.log('shareTicket', res);
        },
        fail: function (res) {
          resolve();
        },
        complete: function (res) { },
      })
    })
  },

  checkSession() {
    return new Promise((resolve, reject) => {
      let options = {};
      options.success = resolve;
      options.fail = reject;
      wx.checkSession(options);
    })
  },

  getShareGroup: (shareTicket) => {
    // console.log('app', app);
    //获取加密code、iv、EncryptedData
    console.log('shareTicket', shareTicket);
    return new Promise((resolve, reject) => {
      if (!shareTicket) {
        resolve({});
        return;
      }
      // group.checkSession()
      //   .then(res => {
      wx.login({
        success: (login) => {
          wx.getShareInfo({
            shareTicket,
            success: (res) => {
              let data = {
                Code: login.code,
                EncryptedData: res.encryptedData,
                IV: res.iv
              }
              resolve(data);

            },
            fail: (err) => {
              resolve({});
            }
          })

          // })
          // .catch(res=>{

          // })
        },
        fail: (err) => {
          resolve({});
          // resolve({ errCode: 200, msg: 'Invalid shareTicket' });
        }
      });
    });
  },
}

module.exports = group